home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / disk / misc / ADFlib.lha / Lib / adf_env.c < prev    next >
C/C++ Source or Header  |  1999-05-24  |  5KB  |  198 lines

  1. /*
  2.  * ADF Library
  3.  *
  4.  * adf_env.c
  5.  *
  6.  */
  7.  
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10.  
  11. #include"adf_defs.h"
  12. #include"adf_str.h"
  13. #include"adf_nativ.h"
  14. #include"adf_env.h"
  15.  
  16. #include"defendian.h"
  17.  
  18. union u{
  19.     long l;
  20.     char c[4];
  21.     };
  22.  
  23. ENV_DECLARATION;
  24.  
  25.  
  26. void Warning(char* msg) {
  27.     fprintf(stderr,"Warning <%s>\n",msg);
  28. }
  29.  
  30. void Error(char* msg) {
  31.     fprintf(stderr,"Error <%s>\n",msg);
  32. //    exit(1);
  33. }
  34.  
  35. void Verbose(char* msg) {
  36.     fprintf(stderr,"Verbose <%s>\n",msg);
  37. }
  38.  
  39. void Changed(SECTNUM nSect, int changedType)
  40. {
  41. /*    switch(changedType) {
  42.     case ST_FILE:
  43.         fprintf(stderr,"Notification : sector %ld (FILE)\n",nSect);
  44.         break;
  45.     case ST_DIR:
  46.         fprintf(stderr,"Notification : sector %ld (DIR)\n",nSect);
  47.         break;
  48.     case ST_ROOT:
  49.         fprintf(stderr,"Notification : sector %ld (ROOT)\n",nSect);
  50.         break;
  51.     default:
  52.         fprintf(stderr,"Notification : sector %ld (???)\n",nSect);
  53.     }
  54. */}
  55.  
  56. /*
  57.  * adfInitEnv
  58.  *
  59.  */
  60. void adfEnvInitDefault()
  61. {
  62. //    char str[80];
  63.     union u val;
  64.  
  65.     /* internal checking */
  66.  
  67.     if (sizeof(short)!=2) 
  68.         { fprintf(stderr,"Compilation error : sizeof(short)!=2\n"); exit(1); }
  69.     if (sizeof(long)!=4) 
  70.         { fprintf(stderr,"Compilation error : sizeof(short)!=2\n"); exit(1); }
  71.     if (sizeof(struct bEntryBlock)!=512)
  72.         { fprintf(stderr,"Internal error : sizeof(struct bEntryBlock)!=512\n"); exit(1); }
  73.     if (sizeof(struct bRootBlock)!=512)
  74.         { fprintf(stderr,"Internal error : sizeof(struct bRootBlock)!=512\n"); exit(1); }
  75.     if (sizeof(struct bDirBlock)!=512)
  76.         { fprintf(stderr,"Internal error : sizeof(struct bDirBlock)!=512\n"); exit(1); }
  77.     if (sizeof(struct bBootBlock)!=1024)
  78.         { fprintf(stderr,"Internal error : sizeof(struct bBootBlock)!=1024\n"); exit(1); }
  79.     if (sizeof(struct bFileHeaderBlock)!=512)
  80.         { fprintf(stderr,"Internal error : sizeof(struct bFileHeaderBlock)!=512\n"); exit(1); }
  81.     if (sizeof(struct bFileExtBlock)!=512)
  82.         { fprintf(stderr,"Internal error : sizeof(struct bFileExtBlock)!=512\n"); exit(1); }
  83.     if (sizeof(struct bOFSDataBlock)!=512)
  84.         { fprintf(stderr,"Internal error : sizeof(struct bOFSDataBlock)!=512\n"); exit(1); }
  85.     if (sizeof(struct bBitmapBlock)!=512)
  86.         { fprintf(stderr,"Internal error : sizeof(struct bBitmapBlock)!=512\n"); exit(1); }
  87.     if (sizeof(struct bBitmapExtBlock)!=512)
  88.         { fprintf(stderr,"Internal error : sizeof(struct bBitmapExtBlock)!=512\n"); exit(1); }
  89.     if (sizeof(struct bLinkBlock)!=512)
  90.         { fprintf(stderr,"Internal error : sizeof(struct bLinkBlock)!=512\n"); exit(1); }
  91.  
  92.     val.l=1L;
  93. /* if LITT_ENDIAN not defined : must be BIG endian */
  94. #ifndef LITT_ENDIAN
  95.     if (val.c[3]!=1) /* little endian : LITT_ENDIAN must be defined ! */
  96.         { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must exist\n"); exit(1); }
  97. #else
  98.     if (val.c[3]==1) /* big endian : LITT_ENDIAN must not be defined ! */
  99.         { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must not exist\n"); exit(1); }
  100. #endif
  101.  
  102.     adfEnv.wFct = Warning;
  103.     adfEnv.eFct = Error;
  104.     adfEnv.vFct = Verbose;
  105.     adfEnv.notifyFct = Changed;
  106.  
  107.     adfEnv.useDirCache = FALSE;
  108.  
  109. /*    sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate());
  110.     (*adfEnv.vFct)(str);
  111. */
  112.     adfEnv.nativeFct=(struct nativeFunctions*)malloc(sizeof(struct nativeFunctions));
  113.     if (!adfEnv.nativeFct) (*adfEnv.wFct)("adfInitDefaultEnv : malloc");
  114.  
  115.     adfInitNativeFct();
  116. }
  117.  
  118.  
  119. /*
  120.  * adfEnvCleanUp
  121.  *
  122.  */
  123. void adfEnvCleanUp()
  124. {
  125.     free(adfEnv.nativeFct);
  126. }
  127.  
  128.  
  129. /*
  130.  * adfChgEnvProp
  131.  *
  132.  */
  133. void adfChgEnvProp(int prop, void *new)
  134. {
  135.     BOOL *newBool;
  136.  
  137.     switch(prop) {
  138.     case PR_VFCT:
  139.         adfEnv.vFct = (void(*)(char*))new;
  140.         break;
  141.     case PR_WFCT:
  142.         adfEnv.wFct = (void(*)(char*))new;
  143.         break;
  144.     case PR_EFCT:
  145.         adfEnv.eFct = (void(*)(char*))new;
  146.         break;
  147.     case PR_NOTFCT:
  148.         adfEnv.notifyFct = (void(*)(SECTNUM,int))new;
  149.         break;
  150.     case PR_USEDIRC:
  151.         newBool = (BOOL*)new;
  152.         adfEnv.useDirCache = *newBool;
  153.         break;
  154.     }
  155. }
  156.  
  157. /*
  158.  *  adfSetEnv
  159.  *
  160.  */
  161. void adfSetEnvFct( void(*eFct)(char*), void(*wFct)(char*), void(*vFct)(char*),
  162.     void(*notFct)(SECTNUM,int)  )
  163. {
  164.     if (*eFct!=0)
  165.         adfEnv.eFct = *eFct;
  166.     if (*wFct!=0)
  167.         adfEnv.wFct = *wFct;
  168.     if (*vFct!=0)
  169.         adfEnv.vFct = *vFct;
  170.     if (*notFct!=0)
  171.         adfEnv.notifyFct = *notFct;
  172. }
  173.  
  174.  
  175. /*
  176.  * adfGetVersionNumber
  177.  *
  178.  */
  179. char* adfGetVersionNumber()
  180. {
  181.     return(ADFLIB_VERSION);
  182. }
  183.  
  184.  
  185. /*
  186.  * adfGetVersionDate
  187.  *
  188.  */
  189. char* adfGetVersionDate()
  190. {
  191.     return(ADFLIB_DATE);
  192. }
  193.  
  194.  
  195.  
  196.  
  197. /*##################################################################################*/
  198.